package com.example.app3.recyclerView;

import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.example.app3.R;
import com.example.app3.recyclerView.domain.Template;
import com.example.app3.util.Init;

import java.util.ArrayList;
import java.util.List;


public class ContentActivity extends AppCompatActivity {
    private List<Template> list = new ArrayList<>();


    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.content);
        initTemplate();
        RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerview);
        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        recyclerView.setLayoutManager(layoutManager);
        ContentAdapter adapter = new ContentAdapter(list);
        recyclerView.setAdapter(adapter);


    }

    private void initTemplate() {
        ArrayList<Object> imageIds = new ArrayList<>();
        ArrayList<String> text= Init.initChoices();

        //批量获取id
        for (int i = 1; i < 7; i++) {
            int id = getResources().getIdentifier("con" + i, "drawable", getPackageName());

            imageIds.add(id);
        }

        //拼凑形成页面
        for (int i = 0; i < 6; i++) {
            Template template = new Template((int)imageIds.get(i), text.get(i));
            list.add(template);
        }
    }

}
